/*
 * Copyright (c) 2017, Li Bo/Alex Lee All rights reserved.
 * 
 * http://www.libo4dream.club/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.hyts.fscan.deal;

import java.io.File;
import java.io.FilenameFilter;
import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName: RecursiveLoader
 * @Description: TODO
 * @author: LiBo/Alex Lee
 * @date: 2017年9月30日 下午11:20:00
 * @email: alexlibochn@china-pui.com.cn/alex.link@foxmail.com
 */
public class RecursiveLoader {
	
	/**
	 * @fieldName: path
	 * @fieldType: String
	 * @Description: 路径
	 */
	private String path;

	/**
	 * @fieldName: filter
	 * @fieldType: FilenameFilter
	 * @Description: 文件名称过滤器
	 */
	private FilenameFilter filter;
	
	/**
	 * @fieldName: fileArray
	 * @fieldType: File[]
	 * @Description: 文件数组
	 */
	private List files;
	
	/**
	 * @Title:NonRecursiveLoader
	 * @Description:非递归进行加载器
	 * @param directorys
	 */
	public RecursiveLoader(FilenameFilter filter) {
		this.filter = filter;
		files = new LinkedList();
	}
	
	/**
	 * @Title:NonRecursiveLoader
	 * @Description:TODO
	 * @param path
	 */
	public RecursiveLoader() {
		files = new LinkedList();
	}
	
	
	public void scanFile(String path)
	{
		File dirFile = new File(path);
		if(dirFile.exists()){
			File[] fileList = filter == null ? dirFile.listFiles():dirFile.listFiles(filter);
			for(File file:fileList){
				if(file.isDirectory()){
					scanFile(file.getPath());
				}
				else
				{
					files.add(file);
				}
			}
		}
	}

	public List getFiles() {
		return files;
	}
	 
}
